package org.example.jdbcOperator.util;

public class StringUtil {

    /**
     * 将驼峰命名的字符串转换为下划线字符串
     */
    public static String convertToUnderline(String str) {
        if (str.isEmpty()) return null;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (Character.isUpperCase(c)) {
                if (i == 0) {
                    sb.append(Character.toLowerCase(c));
                } else {
                    sb.append('_');
                    sb.append(Character.toLowerCase(c));
                }
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }
}
